import { http } from "@/utils/http";
import {ListPageResult, ListResult} from "./models";

/** 获取内容列表 */
export interface LeadsListResult{
  uuid: string
  name: string
  mobile: string
  company?: string
  source: string
  headimgurl: string
  leads_date: string
  leads_phase: string
  leads_status_uuid: string
  leads_status: string
  work_external_userid: string
}
export const LeadsList = (params?: object) => {
  return http.request<ListPageResult<LeadsListResult>>("get", "/api/open/nurturing/leads/leads", {
    params
  });
}





/** 获取状态列表 */
export interface StatusLeads {
  id: string
  text: string
  children:StatusLeads[]
}
export const StatusList = (prepend:boolean=true) => {
  return http.request<ListResult<StatusLeads[]>>("get", `/api/open/nurturing/leads/status/all?prepend=${prepend}`);
};


/** 获取状态列表 */
export interface LeadsAddType {
  uuid:string
  name:string
}
export const LeadsAdd = (data:object) => {
  return http.request<ListResult<LeadsAddType>>("post", "/api/open/nurturing/leads/leads",{
    data
  });
};




/** 获取状态列表 */
export interface FieldType{
  id:number
  code:string
  name:string
  value:string
}
export interface TagType{
  id:number
  name:string
}
export interface RecordType{
  name:string
  date:string
}
export interface BasicInfo{
  name:string
  mobile:string
  company:string
  email:string
  position:string
}

export interface LeadsInfoType {
  uuid: string
  name: string
  source: string
  mobile: string
  headimgurl: string
  fields: FieldType[]
  tags: TagType[]
  record: RecordType[]
  leads_phase: string
  leads_status_uuid: string
  leads_status: string
  assign_sale_uuid: string
  basic_info?:BasicInfo
}
export const LeadsShow = (uuid:string) => {
  return http.request<ListResult<LeadsInfoType>>("get", `/api/open/nurturing/leads/leads/${uuid}`);
};








export interface Recognition {
  name:string
  mobile:string
  email:string
  company:string
  position:string
  address:string
  telephone:string
}
export const CardRecognition = (data:object) => {
  return http.request<ListResult<Recognition>>("post", "/api/open/nurturing/leads/card/recognition",{
    data
  });
};


/** 更新状态和备注 */
export interface StatusUpdateType {
  status: number
}
export interface StatusUpdateDataType {
  sale_uuid: string
  uuid: string
  content: string
}
export const StatusUpdate = (uuid:string,data:StatusUpdateDataType) => {
  return http.request<ListResult<StatusUpdateType>>("put", `/api/open/nurturing/leads/updateStatus/${uuid}`,{
    data
  });
};


/** 更新备注 */
export interface RemarkUpdateType {
  status: number
}
export interface RemarkUpdateDataType {
  sale_uuid:string
  content: string
}
export const RemarkUpdate = (uuid:string,data:RemarkUpdateDataType) => {
  return http.request<ListResult<RemarkUpdateType>>("put", `/api/open/nurturing/leads/updateRemark/${uuid}`,{
    data
  });
};


/** 更新备注 */
export interface LeadsAssignType {
  status: number
}
export interface LeadsAssignDataType {
  sale_uuid: string
}
export const LeadsAssign = (uuid:string,data:LeadsAssignDataType) => {
  return http.request<ListResult<LeadsAssignType>>("put", `/api/open/nurturing/leads/assign/${uuid}`,{
    data
  });
};



/** 分析 */
export interface LeadsAnalysisChartType {
  phase: {
    yAxisData:any,
    seriesData:any
  },
  phaseFunnel:{
    yAxisData:any,
    seriesData:any
  },
  status: {
    yAxisData:any,
    seriesData:any
  }
}
export interface LeadsAnalysisDataType {
  sale_uuid: string
  start: string
  end: string
}
export const LeadsAnalysisChart = (data:LeadsAnalysisDataType) => {
  return http.request<ListResult<LeadsAnalysisChartType>>("post", `/api/open/nurturing/leads/analysis/chart`,{
    data
  });
};



export interface LeadsAnalysisTotalType {
  saleNotFollow:number
  transferOut:number
  saleNew:number
  poolUnFollow:number
  poolNew:number
  recycle:number
}
export interface LeadsAnalysisDataType {
  sale_uuid: string
  start: string
  end: string
}
export const LeadsAnalysisTotal = (data:LeadsAnalysisDataType) => {
  return http.request<ListResult<LeadsAnalysisTotalType>>("post", `/api/open/nurturing/leads/analysis/total`,{
    data
  });
};


/** 获取内容列表 */
export interface LeadsRecordListResult{
  dateGroup?: string
  date?: string
  title?: string
  icon?: string
  action_type?: string
  iconBgColor?: string
  status?: string
  remark?: string
  saleHeadimgurl?: string
  saleName?: string
  operate?: string
  time?: string
}
export const LeadsRecordList = (uuid:string,type: string) => {
  return http.request<ListResult<LeadsRecordListResult[]>>("get", `/api/open/middledomain/action/${uuid}/${type}`);
}